package cn.whit.blog.servlet;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.whit.blog.domain.Tcommit;
import cn.whit.blog.domain.User;
import cn.whit.blog.service.TcommitService;
import cn.whit.blog.util.BeanFactory;
import cn.whit.blog.util.MyBeanUtils;

public class TcommitServlet extends BaseServlet {

	private static final long serialVersionUID = -5714457999435985381L;
	
	TcommitService tcommitService = (TcommitService) BeanFactory.createObject("tcommitService");

	// 新增评论 
	public String add(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String blogid = request.getParameter("blogid");
		Tcommit tcommit = MyBeanUtils.populate(Tcommit.class, request.getParameterMap());
		tcommit.setPublishTime(new Date());
		//记录评论的人的信息
		User loginUser =  (User) request.getSession().getAttribute("loginUser");
		tcommit.setCommituserid(loginUser.getId());
		tcommit.setCommitusername(loginUser.getName());
		//这里需要请求转发到jsp页面，还是请求转发到servlet？
		tcommitService.save(tcommit);
		
		response.sendRedirect("TblogServlet?method=show&id=" + blogid);
		return null;
//		return "TblogServlet?method=show&id=" + blogid;
	}
	 

}
